package com.huike.clues.service.impl;


import com.fasterxml.jackson.databind.deser.ValueInstantiator;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueService;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private ITbClueService iTbClueService;
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    /**
     * 添加跟进记录
     *
     * @param clueTrackRecordVo
     */
    @Override
    public void add(ClueTrackRecordVo clueTrackRecordVo) {
        String username = SecurityUtils.getUsername();

        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(clueTrackRecordVo, tbClue, "id");
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbClue.setId(clueTrackRecordVo.getClueId());
        iTbClueService.updateTbClue(tbClue);

        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        BeanUtils.copyProperties(clueTrackRecordVo, tbClueTrackRecord);
        tbClueTrackRecord.setCreateBy(username);
        tbClueTrackRecordMapper.addtbClueTrackRecord(tbClueTrackRecord);

    }

    /**
     * 查询跟进线索记录
     *
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> recordList(Long clueId) {
        List<TbClueTrackRecord> tbClueTrackRecord =  tbClueTrackRecordMapper.recordList(clueId);
        return tbClueTrackRecord;
    }
}
